<template>
  <!-- 合作设置 推广用户 -->
  <div class="op-container">
    <hq-searchDown
      ref="hqSearchDown"
      :select-opts="selectOpts"
      @click="handleFilter"
    />
    <div class="filter-container">
      <span class="filter-title filter-item">通道</span>
      <k-select
        v-model="listQuery.caseProbability"
        style="width: 120px"
        class="filter-item user-case"
        :select-params="dict.type.ANCHOR_TYPE"
        @handleSelectEvent="$refs.hqSearchDown.searchFun()"
      />
      <span class="filter-title filter-item">用户状态</span>
      <k-select
        v-model="listQuery.userIdStatus"
        style="width: 120px"
        class="filter-item user-status"
        :select-params="[
          { label: '离线', value: 0 },
          { label: '在线', value: 1 },
        ]"
        @handleSelectEvent="$refs.hqSearchDown.searchFun()"
      />
      <span class="filter-title filter-item">账号状态</span>
      <k-select
        v-model="listQuery.userStatus"
        style="width: 120px"
        class="filter-item account-status"
        :select-params="[
          { label: '冻结', value: 0 },
          { label: '开启', value: 1 },
        ]"
        @handleSelectEvent="$refs.hqSearchDown.searchFun()"
      />
      <span class="filter-title filter-item">注册时间</span>
      <k-date-picker
        v-model="timeValue"
        class="filter-item right-item"
        @hqchang="$refs.hqSearchDown.searchFun()"
      />
      <span class="filter-title filter-item">消费时间</span>
      <k-date-picker
        v-model="timeValueGet"
        class="filter-item"
        @hqchang="$refs.hqSearchDown.searchFun()"
      />
      <div style="display: inline-block">
        <span class="filter-title filter-item">VIP等级</span>
        <k-select
          v-model="listQuery.userLevel"
          style="width: 100px"
          class="filter-item account-status"
          :select-params="VIPGradeList"
          @handleSelectEvent="$refs.hqSearchDown.searchFun()"
        />
      </div>
    </div>
    <!-- openAssignAccountDialog -->
    <!-- <k-button
      v-if="authorityHandle(15)"
      class="top-btn"
      value="分配账号"
      @click.native="openAssignAccountDialog"
    /> -->
    <k-button
      v-if="authorityHandle(15)"
      class="top-btn"
      value="亏补设置"
      @click.native="lossSettin"
    />
    <k-button
      v-if="authorityHandle(15)"
      class="top-btn"
      value="分成设置"
      @click.native="splitSettings"
    />
    <div v-else style="margin-top: 40px" />
    <!--表格相关 -->
    <el-table
      :data="listData"
      fit
      border
      show-summary
      :summary-method="getSummaries"
      highlight-current-row
      style="width: 100%; border-radius: 8px"
      :header-cell-style="{ background: '#F6F5FA', color: '#4E4F62' }"
      @sort-change="sortChange"
    >
      <el-table-column min-width="80px" label="头像" align="center">
        <template slot-scope="scope">
          <!-- <el-image style="width: 50px; height: 50px" :src="scope.row.userIcon" fit="contain" /> -->
          <div class="demo-image__preview">
            <KImage
              :imagevalue="scope.row.userIcon"
              width-item="50px"
              height-item="50px"
            />
            <!-- <el-image style="width: 110px; height: 80px" :src="scope.row.userIcon" :preview-src-list="[scope.row.userIcon]" fit="contain" /> -->
          </div>
        </template>
      </el-table-column>
      <el-table-column
        prop="nickName"
        min-width="120px"
        label="昵称"
        align="center"
      />
      <el-table-column
        prop="mobile"
        min-width="120px"
        label="用户名"
        align="center"
      />
      <el-table-column
        prop="ownerInvitation"
        min-width="100px"
        label="推广码"
        align="center"
      />
      <el-table-column
        prop="businessName"
        min-width="100px"
        label="商务合作"
        align="center"
      />
      <el-table-column
        prop="businessIdName"
        min-width="100px"
        label="维护人"
        align="center"
      />
      <el-table-column min-width="100px" label="VIP等级" align="center">
        <template slot-scope="scope">
          <span>
            {{ getOptionLabel(scope.row.userLevel, "VIPGradeList") }}
          </span>
        </template>
      </el-table-column>
      <el-table-column
        prop="turnoverTotal"
        min-width="130px"
        label="总流水(F)"
        sortable="custom"
        show-overflow-tooltip
        align="center"
      >
        <template slot-scope="scope">
          <div>
            {{ scope.row.fissionTotal }}
            <span style="color: #3b425d; cursor: pointer" @click="clickDetail"
              >详情</span
            >
          </div>
        </template>
      </el-table-column>
      <el-table-column
        prop="rechargeTotal"
        min-width="120px"
        label="个人总消费(R)"
        sortable="custom"
        align="center"
      />
      <el-table-column
        prop="expendTotal"
        min-width="120px"
        label="全部总消费(R)"
        sortable="custom"
        align="center"
      />
      <el-table-column
        prop="accountBalance"
        min-width="100px"
        label="积分余额(F)"
        sortable="custom"
        align="center"
      />
      <el-table-column
        prop="ammoBalance"
        min-width="100px"
        label="晶粹余额(J)"
        sortable="custom"
        align="center"
      />
      <!-- <el-table-column min-width="150px" label="95余额" align="center">
        <template slot-scope="scope">
          <div style="display: flex; align-items: center; justify-content: center;">
            <p>{{ scope.row.accountBalance }}</p><i
              v-if="authorityHandle(179)"
              style="margin-left: 6px; font-size: 20px; cursor: pointer;"
              class="el-icon-edit"
              @click="setUserBalanceShow(scope.row)"
            />
          </div>
        </template>
      </el-table-column> -->
      <!-- <el-table-column
        min-width="100px"
        label="背包价值"
        align="center"
      >
        <el-table-column prop="flRucksackTotal" min-width="80px" label="福利成本" sortable="custom" align="center" />
        <el-table-column prop="zpRucksackTotal" min-width="80px" label="赠品成本" sortable="custom" align="center" />
      </el-table-column> -->
      <!-- <el-table-column prop="accountBalanceTwo" min-width="80px" label="元宝余额" show-overflow-tooltip align="center" /> -->
      <!-- <el-table-column prop="turnoverTotal" min-width="100px" label="流水总额"  align="center" /> -->
      <el-table-column
        v-if="authorityHandle(1)"
        prop="drawTotal"
        min-width="120px"
        sortable="custom"
        label="提取成本总额(R)"
        align="center"
      />
      <el-table-column
        v-if="authorityHandle(1)"
        prop="drawPercent"
        min-width="120px"
        label="提取百分比"
        show-overflow-tooltip
        align="center"
        sortable="custom"
      >
        <template slot-scope="scope"> {{ scope.row.drawPercent }}% </template>
      </el-table-column>
      <el-table-column
        prop="assetCardCount"
        min-width="100px"
        label="数字卡总数"
        align="center"
      />
      <el-table-column
        prop="caseProbabilityName"
        min-width="100px"
        label="通道"
        align="center"
      />
      <el-table-column
        prop="userIdStatusName"
        min-width="100px"
        label="用户状态"
        align="center"
      />
      <el-table-column
        prop="createTime"
        min-width="150px"
        label="注册时间"
        sortable="custom"
        align="center"
      />
      <el-table-column
        prop="userStatusName"
        min-width="100px"
        label="账号状态"
        align="center"
      />
      <el-table-column min-width="150px" label="主播名称" align="center">
        <template slot-scope="scope">
          <div
            style="display: flex; align-items: center; justify-items: center"
          >
            <p class="kol-router" @click="routerGoDetail(scope.row.id)">
              {{ scope.row.anchorName }}
            </p>
            <!-- <k-button class="top-btn" value="复制" @click.native="openAssignAccountDialog" /> -->
            <i
              v-clipboard:copy="strFilter(scope.row.anchorName)"
              v-clipboard:success="copy"
              v-clipboard:error="onError"
              style="margin-left: 4px; cursor: pointer"
              class="el-icon-document-copy"
            />
          </div>
        </template>
      </el-table-column>
      <el-table-column
        v-if="authorityHandle(15)"
        prop="describe"
        min-width="120px"
        label="备注"
        align="center"
      >
        <editable-cell
          v-model="row.describe"
          slot-scope="{ row }"
          :tool-tip-content="
            row.describe ? row.describe : '点击编辑,编辑完成回车'
          "
          :show-input="row.editMode"
          @blur="blurInput(row)"
          @keyup.enter.native="$event.target.blur()"
        >
          <span
            slot="content"
            style="
              overflow: hidden;
              white-space: nowrap;
              text-overflow: ellipsis;
            "
            >{{ row.describe }}</span
          >
        </editable-cell>
      </el-table-column>

      <el-table-column
        v-else
        prop="describe"
        min-width="120px"
        label="备注"
        align="center"
      />
      <el-table-column
        prop="reason"
        min-width="120px"
        label="冻结原因"
        align="center"
      />
      <el-table-column
        v-if="authorityHandle(15)"
        min-width="120px"
        label="IP限制"
        align="center"
      >
        <template slot-scope="{ row }">
          <div class="finger-container">
            <span>{{ row.isImpose ? "是" : "否" }}</span>
            <p class="finger-delete" @click="relieveIS(row)">
              {{ row.isImpose ? "解除" : "" }}
            </p>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        v-if="authorityHandle(15)"
        min-width="120px"
        label="设备限制"
        align="center"
      >
        <template slot-scope="{ row }">
          <div class="finger-container">
            <editable-cell
              v-model="row.fingerprintCount"
              :show-input="row.editMode"
              @keyup.enter.native="upDateFingerCount(row)"
            >
              <span slot="content" class="content">{{
                row.fingerprintCount
              }}</span>
            </editable-cell>
            <p class="finger-delete" @click="clearFinger(row)">清空</p>
          </div>
        </template>
      </el-table-column>

      <el-table-column
        v-else
        prop="fingerprintCount"
        min-width="120px"
        label="设备限制"
        align="center"
      />

      <el-table-column
        min-width="350px"
        fixed="right"
        label="操作"
        align="center"
      >
        <template slot-scope="scope">
          <div class="op-div">
            <k-button
              class="table-btn"
              value="修改/详情"
              @click.native="userUpdateDialog(scope.row)"
            />
            <!-- <k-button
              v-if="authorityHandle(180)"
              class="table-btn"
              value="清空背包"
              @click.native="userCleanrksack(scope.row)"
            /> -->
            <k-button
              v-show="authorityHandle([16,17,18],false)&&scope.row.userStatusInt !== 0"
              class="table-btn"
              :value="'冻结'"
              @click.native="updateStatus(scope.row)"
            />
            <k-button
              v-show="authorityHandle([16,17,18],false)&&scope.row.userStatusInt === 0"
              class="table-btn"
              :value="'解冻'"
              @click.native="updateStatus(scope.row, '1')"
            />
            <!-- <k-button
              v-if="authorityHandle(15)"
              class="table-btn"
              :value="
                scope.row.fissionLimitLogin === 0 ? '限制登录' : '正常登录'
              "
              @click.native="limitLogin(scope.row)"
            /> -->
            <k-button
              v-if="authorityHandle(15)"
              class="table-btn"
              :value="'取消合作'"
              @click.native="cancelCooperation(scope.row)"
            />
          </div>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="totalRows > 0"
      :total="totalRows"
      :page.sync="listQuery.pager.pageNo"
      :limit.sync="listQuery.pager.pageSize"
      @pagination="$refs.hqSearchDown.searchFun(1)"
    />
    <!-- 分配账号 弹窗 -->
    <k-dialog
      :show-hide.sync="openAssignAccount.showHide"
      :modal-append-to-body="false"
      :append-to-body="true"
      :title="textMap[dialogStatus]"
      :show-foot="false"
      :two-btn="authorityHandle(15)"
      :close-fun="closeFun"
      @click="assignAccount"
    >
      <el-form
        ref="formName"
        :model="koluserinfo"
        label-width="auto"
        :rules="modifyrules"
        class="form-modify"
      >
        <div class="modify-left">
          <el-form-item label="用户名：" prop="mobile">
            <el-input
              v-model="koluserinfo.mobile"
              :readonly="!authorityHandle(15)"
              placeholder="建议字母+数字"
            />
          </el-form-item>
          <el-form-item label="头像：">
            <k-upload-file
              ref="upload1"
              v-model="codeValue1"
              class="avatar_robot"
              upload-style="img"
              @successUpload="successUpload"
            />
            <span style="color: #b2b2b2; font-size: 10sp"
              >jpg/png，且不超过2M</span
            >
          </el-form-item>
          <el-form-item label="密码：" prop="password">
            <el-input
              v-model="koluserinfo.password"
              :readonly="!authorityHandle(15)"
              show-password
              placeholder="建议字母+数字"
            />
          </el-form-item>
          <el-form-item label="昵称：" prop="nickName">
            <el-input
              v-model="koluserinfo.nickName"
              :readonly="!authorityHandle(15)"
              placeholder="请输入昵称"
            />
          </el-form-item>
          <el-form-item label="绑定第三方账号：">
            <el-input
              v-model="koluserinfo.steamId"
              :readonly="!authorityHandle(15)"
              placeholder="请输入第三方账号"
            />
          </el-form-item>
          <el-form-item label="交易链接：">
            <el-input
              v-model="koluserinfo.steamUrl"
              :readonly="!authorityHandle(15)"
              placeholder="请输入交易链接"
            />
          </el-form-item>
          <el-form-item label="真实姓名：">
            <el-input
              v-model="koluserinfo.userName"
              :readonly="!authorityHandle(15)"
              placeholder="请输入真实姓名"
            />
          </el-form-item>
          <el-form-item label="身份证号：">
            <el-input
              v-model="koluserinfo.idNumber"
              :readonly="!authorityHandle(15)"
              placeholder="请输入身份证号"
            />
          </el-form-item>
          <el-form-item label="推广码：" prop="ownerInvitation">
            <el-input
              v-model="koluserinfo.ownerInvitation"
              :readonly="!authorityHandle(15)"
              placeholder="请输入推广码"
            />
          </el-form-item>
        </div>
        <div class="modify-right">
          <el-form-item label="商务合作：" prop="businessName">
            <el-input
              v-model="koluserinfo.businessName"
              :readonly="!authorityHandle(15)"
              placeholder="请选择商务合作"
            />
            <!-- <el-select
              v-model="koluserinfo.businessName"
              :disabled="!authorityHandle(15)"
              placeholder="请选择商务合作"
            >
              <el-option
                v-for="item in adminData"
                :key="item.lineId"
                :label="item.lineName"
                :value="item.lineId"
              />
            </el-select> -->
          </el-form-item>

          <el-form-item label="维护人：" prop="businessId">
            <el-select
              v-model="koluserinfo.businessId"
              :disabled="!authorityHandle(15)"
              placeholder="请选择概率"
            >
              <el-option
                v-for="item in adminData"
                :key="item.lineId"
                :label="item.lineName"
                :value="item.lineId"
              />
            </el-select>
          </el-form-item>

          <!-- <el-form-item label="95余额：">
            <el-input
              v-model="koluserinfo.accountBalance"
              :readonly="!authorityHandle(15)"
              onkeyup="value=value.replace(/[^0-9.]/g,'')"
              placeholder="请输入95余额"
            />
          </el-form-item>
          <el-form-item label="晶粹数量：">
            <el-input
              v-model="koluserinfo.ammoBalance"
              :readonly="!authorityHandle(15)"
              onkeyup="value=value.replace(/[^0-9.]/g,'')"
              placeholder="请输入晶粹数量"
            />
          </el-form-item>
          <el-form-item label="元宝余额：">
            <el-input
              v-model="koluserinfo.accountBalanceTwo"
              :readonly="!authorityHandle(15)"
              onkeyup="value=value.replace(/[^0-9.]/g,'')"
              placeholder="请输入元宝余额"
            />
            <k-button
              v-if="authorityHandle(15)"
              class="balance_btn"
              value="保存"
              @click.native="saveAccountBalance(3,koluserinfo.accountBalanceTwo)"
            />
          </el-form-item> -->
          <el-form-item label="通道：" prop="caseProbability">
            <el-select
              v-model="koluserinfo.caseProbability"
              :disabled="!authorityHandle(15)"
              placeholder="请选择概率"
            >
              <el-option
                v-for="item in dict.type.ANCHOR_TYPE"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="主播名称：">
            <el-input
              v-model="koluserinfo.anchorName"
              :readonly="!authorityHandle(15)"
              placeholder="请输入名称"
            />
          </el-form-item>
          <!-- <el-form-item label="用户等级：">
            <el-select v-model="koluserinfo.userLevel" :disabled="!authorityHandle(15)" placeholder="请选择">
              <el-option v-for="item in gradeOptions" :key="item.lineId" :label="item.lineName" :value="item.lineId" />
            </el-select>
          </el-form-item> -->
          <!-- <el-form-item label="vip等级：">
            <el-select
              v-model="koluserinfo.userLevel"
              :disabled="!authorityHandle(15)"
              placeholder="请选择"
            >
              <el-option
                v-for="item in VIPGradeList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item> -->
          <!-- <el-form-item label="手机号：">
            <el-input v-model="koluserinfo.anchorName" :readonly="!authorityHandle(15)" placeholder="请输入手机号" />
          </el-form-item>
          <el-form-item label="后台密码：">
            <el-input v-model="koluserinfo.anchorName" :readonly="!authorityHandle(15)" placeholder="请输入后台密码" />
          </el-form-item> -->
          <!-- <el-form-item label="流水分成：" prop="totalShare">
            <div class="percent-div">
              <el-input
                v-model="koluserinfo.totalShare"
                :readonly="!authorityHandle(15)"
                onkeyup="value=value.replace(/[^0-9.]/g,'')"
                placeholder="请输入数值"
              />
              <span>%</span>
            </div>
          </el-form-item> -->
          <!-- <el-form-item label="所属团队：">
            <el-select v-model="koluserinfo.teamId" placeholder="请选择">
              <el-option v-for="item in TeamList" :key="item.id" :label="item.name" :value="item.id" />
            </el-select>
          </el-form-item> -->
        </div>
      </el-form>
    </k-dialog>

    <!-- 管理账户余额 弹框 -->
    <k-dialog
      :show-hide.sync="accountBalanceShow"
      :modal-append-to-body="false"
      :append-to-body="true"
      title="管理账户余额"
      :show-foot="false"
      :two-btn="true"
      @click="saveAccountBalance"
    >
      <div class="supervise-container">
        <el-form label-width="auto">
          <el-form-item label="选择变更类型：">
            <el-select v-model="accountValue" placeholder="选择变更类型">
              <el-option
                v-for="(item, index) in options"
                :key="index"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="当前账户余额：">
            <el-input v-model="userBalance" readonly />
          </el-form-item>

          <el-form-item
            v-if="accountValue == 'increase'"
            label="请选择增加金额："
          >
            <el-select
              v-model="increaseSize"
              clearable
              placeholder="请选择增加金额"
            >
              <el-option
                v-for="(item, index) in increaseData"
                :key="index"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>

          <!-- 					<el-form-item v-if="accountValue == 'reduce'" label="请输入减少金额：">
						<el-input v-model="reduceUserBalance" placeholder="请输入减少金额" onkeyup="value=value.replace(/[^0-9.]/g,'')"/>
					</el-form-item> -->

          <el-form-item
            v-if="accountValue == 'increase'"
            label="增加后账户余额："
          >
            <el-input v-model="changeUserBalance" readonly />
          </el-form-item>

          <el-form-item v-if="accountValue == 'reduce'" label="目标账户余额：">
            <el-input v-model="changeUserBalance" />
          </el-form-item>
        </el-form>
      </div>
    </k-dialog>
    <!-- 冻结 -->
    <k-dialog
      :show-hide.sync="shipments.showHide"
      :modal-append-to-body="false"
      :append-to-body="true"
      title="冻结账号"
      class="customBaby-dialog"
      :show-foot="false"
      :two-btn="true"
      @click="saveshipments"
    >
      <el-form :model="shipmentsInfo" label-width="auto">
        <el-form-item label="冻结账号原因：" prop="exteriorId">
          <div style="display: flex">
            <el-input
              v-model="shipmentsInfo.content"
              style="margin-right: 10px"
              placeholder="请输入冻结账号原因"
            />
          </div>
        </el-form-item>
      </el-form>
    </k-dialog>
    <!-- 亏补设置弹窗 -->
    <k-dialog
      :show-hide.sync="lossSettinShow.showHide"
      :modal-append-to-body="false"
      :append-to-body="true"
      title="亏补设置"
      class="customBaby-dialog"
      :show-foot="false"
      :contentShow="authorityHandle(457)"
      :two-btn="authorityHandle(458)"
      @click="lossSettinShowBtn"
    >
      <div>亏补=</div>
      <div style="margin: 20px 0">
        <span>历史总亏损 ( 消耗 - 提取 - 背包 - 回收) * </span
        ><el-input
          v-model="loss"
          placeholder="请输入"
          style="width: 100px"
          oninput="value=value.replace(/[^0-9.]/g,'')"
        ></el-input
        ><span>% -历史总亏补</span>
      </div>
      <div style="color: #d9001b">每日凌晨00：30点结算。</div>
    </k-dialog>
    <!-- 分成设置弹窗 -->
    <k-dialog
      :show-hide.sync="splitSettingsShowDialog"
      :modal-append-to-body="false"
      :append-to-body="true"
      title="分成设置"
      class="customBaby-dialog"
      :show-foot="false"
      :contentShow="authorityHandle(457)"
      :two-btn="authorityHandle(458)"
      @click="splitSettingsShowBtn"
    >
    <div style="margin-bottom: 10px;">
      D+1流水分成比例:  
      <el-input
        v-model="splitSettingsShow.extensionPercent"
        placeholder="请输入"
        style="width: 60px"
        oninput="value=value.replace(/[^0-9.]/g,'')"
      ></el-input>
    </div>

    <div>周一结算比例:</div>
      <div
        style="margin: 10px 0"
        v-for="(item, index) in splitSettingsShow.weekList"
        :key="index"
      >
        <span>消费 （ </span>
        <el-input
          v-model="item.minRecharge"
          placeholder="请输入"
          style="width: 60px"
          oninput="value=value.replace(/[^0-9.]/g,'')"
        ></el-input>
        -
        <el-input
          v-model="item.maxRecharge"
          placeholder="请输入"
          style="width: 60px"
          oninput="value=value.replace(/[^0-9.]/g,'')"
        ></el-input>
        】
        <span style="margin-left: 15px;">流水 * 分成比例 </span>
        <el-input
          v-model="item.totalShare"
          placeholder="请输入"
          style="width: 60px"
          oninput="value=value.replace(/[^0-9.]/g,'')"
        ></el-input>
        <span>%</span>
        <i
          class="el-icon-remove"
          style="font-size: 14px; transform: translateY(1px); cursor: pointer"
          @click="cancelCategory(item, index)"
          v-show="splitSettingsShow.weekList.length > 1"
        />
      </div>
      <k-button class="top-btn" value="添加" @click.native="addCategory" />
      <div style="color: #d9001b">每日凌晨00：30点结算。</div>
    </k-dialog>
  </div>
</template>

<script>
import hqSearchDown from "@/components/hqSearchDown"; // 下拉搜索
import {
  listFissionData,
  update,
  save,
  updateStatus,
  setFingerprintCount,
  clearFingerprint,
  adminList,
  setDescribe,
  usercleanRucksack,
  updateBalance,
  RelieveBanned,
  updateUserAccountBalanceTwo,
  fissionLimitLogin,
  updateFissionToUser,
  getFissionLossSetting,
  setFissionLossSetting,
  getFissionExtensionSetting,
  setFissionExtensionSetting
} from "@/api/user/user";
import { getGradeList } from "@/api/rules/listdata";

import Pagination from "@/components/Pagination";
import EditableCell from "@/components/EditableCell";
// import selectorMes from '@/config/selectorMes' // 配置文件
import vipDataList from "@/views/mixins/data";

export default {
  props: {
    handleClick: {
      type: Function,
    },
  },
  mixins: [vipDataList],

  components: {
    Pagination,
    EditableCell,
    hqSearchDown,
  },
  dicts: ["ANCHOR_TYPE", "SETUSER_LEVEL"],
  data() {
    return {
      // 下拉搜索项0
      selectOpts: [
        {
          label: "昵称",
          value: "nickName",
        },
        {
          label: "用户账号",
          rigth: true,
          value: "mobile",
        },
        {
          label: "推广码",
          value: "ownerInvitation",
        },
        {
          label: "主播名称",
          value: "belongName",
        },
        {
          label: "备注",
          value: "describe",
        },
      ],
      // selectorMes: selectorMes,
      showFingerDel: true,
      dialogStatus: "create",
      textMap: {
        update: "修改/详情",
        create: "分配账号",
      },
      adminData: [], // 维护人---所有管理员
      listData: [],
      invitationCodeList: [],
      gradeOptions: [],
      totalRows: 0, // 分页组件--数据总条数
      listQuery: {
        pager: {
          pageNo: 1,
          pageSize: 10,
          totalRows: "",
          start: "",
          userLevel: "", // 用户等级
        },
        sort: "", // 排序字段 为对应列名,
        direction: "", // 排序 正向(asc)逆向(desc),
        // roleId: 3, // 用户角色",
        identityBelong: undefined, // 身份所属",
        nickName: undefined, // 昵称",
        userIdStatus: undefined, // 在线状态",
        userStatus: "", // 账号状态",
        startTime: "", // 开始时间",
        endTime: "", // 结束时间",
        dataStartTime: "", // 开始时间",
        dataEndTime: "", // 结束时间",
        anchorId: undefined, // 主播id",
        robotStatus: undefined, // AI状态",
        robotExeStatus: undefined, // AI执行状态",
        caseName: "", // 开箱名称",
        caseProbability: undefined, // 用户通道种类"
        invitationCode: "", // 邀请"
        key: "", // 赠品名称'
      },
      koluserinfo: {
        id: undefined,
        roleId: 3,
        mobile: "",
        userIcon: "",
        password: "",
        nickName: "",
        steamId: "",
        steamUrl: "",
        userName: "",
        idNumber: "",
        ownerInvitation: "",
        businessName: "",
        accountBalance: "",
        accountBalanceTwo: "",
        ammoBalance: "",
        businessId: "",
        caseProbability: undefined,
        anchorName: "",
        userLevel: undefined,
        totalShare: undefined,
      },
      modifyrules: {
        mobile: [
          {
            required: true,
            message: "请输入用户名",
            trigger: "blur",
          },
        ],
        ownerInvitation: [
          {
            required: true,
            message: "请输入推广码",
            trigger: "blur",
          },
        ],
        nickName: [
          {
            required: true,
            message: "请输入昵称",
            trigger: "blur",
          },
        ],
        password: [
          {
            required: true,
            message: "请输入密码",
            trigger: "blur",
          },
        ],
        // totalShare: [
        //   {
        //     required: true,
        //     message: "请输入数值",
        //     trigger: "blur",
        //   },
        // ],
        businessName: [
          {
            required: true,
            message: "商务合作必填",
            trigger: "blur",
          },
        ],
        businessId: [
          {
            required: true,
            message: "维护人必选",
            trigger: "blur",
          },
        ],
        caseProbability: [
          {
            required: true,
            message: "用户通道必选",
            trigger: "blur",
          },
        ],
        userLevel: [
          {
            required: true,
            message: "用户等级必选",
            trigger: "blur",
          },
        ],
      },
      timeValue: "",
      timeValueGet: "",
      openAssignAccount: {
        showHide: false,
      },
      // 亏补设置
      lossSettinShow: {
        showHide: false,
      },
      // 分成设置弹窗
      splitSettingsShowDialog:false,
      // 分成设置
      splitSettingsShow: {
        extensionPercent:"",
        weekList: [
          {
            minRecharge: "",
            maxRecharge: "",
            totalShare: "",
          },
        ],
      },
      shipments: {
        showHide: false,
      },
      shipmentsInfo: {
        content: "",
        userStatusInt: "",
        id: "",
      },
      accountBalanceShow: false,
      rowId: "",
      accountValue: "increase",
      options: [
        {
          value: "increase",
          label: "增加余额",
        },
        {
          value: "reduce",
          label: "减少余额",
        },
      ],
      increaseSize: 10,
      increaseData: [
        {
          value: 10,
          label: 10,
        },
        {
          value: 50,
          label: 50,
        },
        {
          value: 100,
          label: 100,
        },
        {
          value: 535,
          label: 535,
        },
        {
          value: 1100,
          label: 1100,
        },
        {
          value: 3300,
          label: 3300,
        },
      ],
      reduceUserBalance: 0, // 要减少的金额
      userBalance: 0, // 当前余额
      changeUserBalance: 0, // 变更后余额
      loss: "", // 亏补设置
      turnoverTotal:"", // 总流水
      rechargeTotal:"", // 个人总消费
      expendTotal:"", // 全部总消费
    };
  },
  computed: {
    codeValue1() {
      return this.koluserinfo.userIcon;
    },
  },
  watch: {
    // 时间赋值
    timeValue(val) {
      this.listQuery.startTime = this.timeValue ? this.timeValue[0] : null;
      this.listQuery.endTime = this.timeValue ? this.timeValue[1] : null;
    },
    timeValueGet(val) {
      this.listQuery.dataStartTime = this.timeValueGet
        ? this.timeValueGet[0]
        : null;
      this.listQuery.dataEndTime = this.timeValueGet
        ? this.timeValueGet[1]
        : null;
    },

    accountValue(val) {
      this.increaseSize = "";
      this.reduceUserBalance = "";
      this.changeUserBalance = this.userBalance;
    },

    increaseSize(val) {
      if (val) {
        this.changeUserBalance = this.addNum(
          Number(this.userBalance),
          Number(val)
        );
      } else {
        this.changeUserBalance = this.userBalance;
      }
    },

    reduceUserBalance(val) {
      if (val) {
        this.changeUserBalance = Number(this.userBalance) - Number(val);
      } else {
        this.changeUserBalance = this.userBalance;
      }
    },
    $route: {
      deep: true,
      handler(val) {
        this.loadData();
        this.getGradeList();
      },
    },
  },
  created() {
    this.loadData();
    this.getGradeList();
  },
  beforeDestroy() {
    localStorage.setItem("pagination", "1");
  },
  methods: {
  
    getSummaries(param) {
      const {
        columns
      } = param
      const sums = []
      columns.forEach((column, index) => {
      console.log(columns);

        if (index === 0) { // 第一列
          sums[index] = '总计'
        } else if (column.property === 'turnoverTotal') {
          sums[index] = this.turnoverTotal
        } else if (column.property === 'rechargeTotal'){
          sums[index] = this.rechargeTotal
        }else if(column.property === 'expendTotal'){
          sums[index] = this.expendTotal
        }else{
          sums[index] = ''
        }
      })
      return sums
    },
    // 取消合作
    cancelCooperation(row) {
      this.$confirm(`确认将【${row.nickName}】转为普通用户吗?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      })
        .then(() => {
          updateFissionToUser({ userId: row.id }).then((result) => {
            if (result.status === 200) this.$message.success("成功");
            this.handleClick({ name: "Anormaluser" });
          });
        })
        .catch(() => {});
    },
    // 限制登录
    limitLogin(data) {
      fissionLimitLogin({ id: data.id }).then((result) => {
        if (result.data.success) {
          this.$message.success("操作成功");
          this.loadData();
        }
      });
    },
    // 冻结账号
    saveshipments() {
      if (this.shipmentsInfo.content.trim().length <= 0) {
        this.$message.error("未写明冻结原因!");
        return;
      }
      updateStatus({
        userId: this.shipmentsInfo.id,
        userStatus: this.shipmentsInfo.userStatusInt === 0 ? 1 : 0,
        reason: this.shipmentsInfo.content,
      }).then((res) => {
        if (res.data.success) {
          this.handlePageFilter();
          this.shipments.showHide = false;
          this.loadData();
          this.$message.success("操作成功");
        } else {
          this.$message.error(res.data.msg);
        }
      });
    },
    /**
     * 解除
     */
    async relieveIS({ mobile }) {
      await RelieveBanned(mobile);
      this.$message.success("操作成功");
      this.$refs.hqSearchDown.searchFun();
    },
    // 余额变动，弹框
    setUserBalanceShow(row) {
      this.rowId = row.id;
      this.userBalance = row.accountBalance;
      this.changeUserBalance = row.accountBalance;
      this.accountValue == "increase";
      this.increaseSize = "";
      this.reduceUserBalance = "";
      this.accountBalanceShow = true;
    },

    saveAccountBalance(flag, two) {
      if (flag === 3) {
        updateUserAccountBalanceTwo({
          id: this.koluserinfo.id,
          accountBalanceTwo: two,
        }).then((res) => {
          if (res.data.success) {
            this.$refs.hqSearchDown.searchFun(1);
            this.$message.success("操作成功");
            // this.modifyDialog.showHide = false
          } else {
            this.$message.error(res.data.msg);
          }
        });
        return;
      }
      const data = {
        id: this.rowId,
      };
      if (this.accountValue == "increase") {
        data.accountBalance = this.increaseSize;
      } else {
        data.accountBalance = this.cutNum(
          this.changeUserBalance,
          this.userBalance
        );
        if (data.accountBalance > 0) {
          this.$message.error("目标余额不可大于当前余额");
          return;
        }
      }
      updateBalance(data).then((res) => {
        if (res.data.success) {
          this.$message.success(res.data.msg);
          this.accountBalanceShow = false;
          this.loadData();
        } else {
          this.$message.error(res.data.msg);
        }
      });
    },

    // +
    addNum(...arr) {
      let floatLength = 0;
      for (let i = 0; i < arr.length; i++) {
        try {
          const currentLength = arr[i].toString().split(".")[1].length;
          if (floatLength < currentLength) {
            floatLength = currentLength;
          }
        } catch (e) {
          console.error("e错误:addNum ", e);
        }
      }

      const m = Math.pow(10, floatLength);
      let endNum = 0;
      for (let k = 0; k < arr.length; k++) {
        endNum += Number(arr[k]) * m;
      }
      return endNum / m;
    },

    // -
    cutNum(...arr) {
      let floatLength = 0;
      for (let i = 0; i < arr.length; i++) {
        try {
          const currentLength = arr[i].toString().split(".")[1].length;
          if (floatLength < currentLength) {
            floatLength = currentLength;
          }
        } catch (e) {
          console.error("e错误:cutNum ", e);
        }
      }
      const m = Math.pow(10, floatLength);

      let endNum = 0;
      for (let k = 0; k < arr.length; k++) {
        if (k == 0) {
          endNum = Number(arr[k]) * m;
        } else {
          endNum = endNum - Number(arr[k]) * m;
        }
      }
      return endNum / m;
    },
    strFilter(arr) {
      if (arr) {
        return arr.toString();
      }
    },
    copy(e) {
      this.$message.success("复制成功");
    },
    onError(e) {
      this.$message.error("复制失败");
    },
    routerGoDetail(kolId) {
      this.$router.push({
        name: "Kolbill",
        params: {
          extensionId: kolId,
        },
      });
    },
    upDateFingerCount(row) {
      setFingerprintCount({
        userId: row.id,
        fingerprintCount: row.fingerprintCount,
      }).then((res) => {
        this.$message.success(res.message);
      });
    },
    clearFinger(row) {
      this.$confirm("确定要清除该用户所有的设备指纹标识么?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          clearFingerprint({
            userId: row.id,
          }).then((res) => {
            this.$message.success(res.message);
          });
        })
        .catch(() => {});
    },
    sortChange(column, prop, order) {
      this.listQuery.sort = column.prop;
      if (column.order === "ascending") {
        this.listQuery.direction = "asc";
      } else if (column.order === "descending") {
        this.listQuery.direction = "desc";
      }
      this.$refs.hqSearchDown.searchFun();
    },
    loadData(v) {
      listFissionData({ ...this.listQuery, ...v }).then((res) => {
        const data = res.data;
        if (data?.rows) {
          this.listData = data.rows.map((row) => {
            return {
              ...row,
              editMode: false,
            };
          });
          this.totalRows = data.totalRows;
          this.turnoverTotal=data.totalData.turnoverTotal// 总流水
          this.rechargeTotal=data.totalData.rechargeTotal // 个人总消费
          this.expendTotal=data.totalData.expendTotal // 全部总消费
        } else {
          this.listData = [];
        }
      });
    },
    blurInput(row) {
      this.modifyItemNote(row);
    },
    // 修改备注
    modifyItemNote(row) {
      // if (!row.describe) return
      setDescribe({
        id: row.id,
        describe: row.describe,
      }).then((res) => {
        if (res.data.success) {
          this.$message.success("备注成功");
        } else {
          this.$message.error(res.data.msg);
        }
      });
    },
    successUpload(data) {
      this.koluserinfo.userIcon = data;
    },
    // 加载用户等级（推广）
    getGradeList() {
      getGradeList().then((res) => {
        this.gradeOptions = res.data;
      });
    },
    // 分配账号
    assignAccount() {
      this.$refs.formName.validate((valid) => {
        if (valid) {
          if (this.dialogStatus === "update") {
            update(this.koluserinfo).then((res) => {
              if (res.data.success) {
                this.handlePageFilter();
                this.$message.success("修改成功");
                this.$resetForm(this.koluserinfo);
                this.openAssignAccount.showHide = false;
              } else {
                this.$message.error(res.data.msg);
              }
            });
          } else {
            save(this.koluserinfo).then((res) => {
              if (res.data.success) {
                this.$refs.hqSearchDown.searchFun();
                this.$message.success("分配成功");
                this.$resetForm(this.koluserinfo);
                this.openAssignAccount.showHide = false;
              } else {
                this.$message.error(res.data.msg);
              }
            });
          }
        }
      });
    },
    closeFun() {
      this.$refs.formName.resetFields();
      this.$resetForm(this.koluserinfo);
    },
    // 修改账号状态
    updateStatus(v, type) {
      if (type == "1") {
        this.$confirm("是否解冻此账号?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            updateStatus({
              userId: v.id,
              userStatus: v.userStatusInt === 0 ? 1 : 0,
              reason: this.shipmentsInfo.content,
            }).then((res) => {
              if (res.data.success) {
                this.handlePageFilter();
                this.shipments.showHide = false;
                this.loadData();
                this.$message.success("操作成功");
              } else {
                this.$message.error(res.data.msg);
              }
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消操作",
            });
          });
      } else {
        this.shipmentsInfo.userStatusInt = v.userStatusInt;
        this.shipmentsInfo.id = v.id;
        this.shipments.showHide = true;
      }
    },
    userUpdateDialog(row) {
      this.dialogStatus = "update";
      this.koluserinfo.id = row.id;
      this.koluserinfo.roleId = 3;
      this.koluserinfo.mobile = row.mobile;
      this.koluserinfo.password = row.showPassword;
      this.koluserinfo.nickName = row.nickName;
      this.koluserinfo.steamId = row.steamId;
      this.koluserinfo.steamUrl = row.steamUrl;
      this.koluserinfo.userIcon = row.userIcon;
      this.koluserinfo.ownerInvitation = row.ownerInvitation;
      this.koluserinfo.userName = row.userName;
      this.koluserinfo.idNumber = row.idNumber;
      this.koluserinfo.businessName = Number(row.businessName);
      this.koluserinfo.accountBalance = row.accountBalance;
      this.koluserinfo.ammoBalance = row.ammoBalance;
      this.koluserinfo.accountBalanceTwo = row.accountBalanceTwo;
      this.koluserinfo.caseProbability = row.caseProbability;
      this.koluserinfo.anchorName = row.anchorName;
      this.koluserinfo.userLevel = row.userLevel;
      this.koluserinfo.totalShare = row.totalShare;
      this.koluserinfo.businessId = row.businessId;
      adminList().then((res) => {
        this.adminData = res.data;
      });
      this.openAssignAccount.showHide = true;
    },

    // 清空背包
    userCleanrksack(row) {
      this.$confirm("确定要清空该用户的背包?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        usercleanRucksack({
          id: row.id,
        })
          .then((res) => {
            if (res.data.success) {
              this.$message.success("操作成功");
              this.$refs.hqSearchDown.searchFun();
            } else {
              this.$message({
                type: "info",
                message: res.data.msg,
              });
            }
          })
          .catch(() => {});
      });
    },

    handlePageFilter() {
      this.listQuery.pager.pageNo =
        Number(localStorage.getItem("pagination")) || 1;
      this.$refs.hqSearchDown.searchFun(1);
    },

    // 搜索查询事件
    handleFilter(v, type) {
      if (type !== 1) this.listQuery.pager.pageNo = 1;
      else localStorage.setItem("pagination", this.listQuery.pager.pageNo);
      this.loadData(v);
    },
    openAssignAccountDialog() {
      this.koluserinfo.roleId = 3;
      this.dialogStatus = "create";
      // 获取所有管理员
      adminList().then((res) => {
        this.adminData = res.data;
      });
      this.openAssignAccount.showHide = true;
    },
    // 亏补设置
    async lossSettin() {
      const res = await getFissionLossSetting();
      if (res.status == 200) this.loss = res.data;
      this.lossSettinShow.showHide = true;
    },
    // 亏补设置按钮
    async lossSettinShowBtn() {
      const res = await setFissionLossSetting({ loss: this.loss });
      if (res.status == 200) this.lossSettinShow.showHide = false;
      this.$message.success("操作成功");
    },
    // 分成设置
    async splitSettings() {
      try {
        const res = await getFissionExtensionSetting();
        if(res.status == 200 && res.data.weekList.length>0) this.splitSettingsShow = res.data;
        this.splitSettingsShowDialog = true;
       } catch (error) {
         this.splitSettingsShowDialog = true;
      }
     
    },
    // 删除一条数据
    cancelCategory(item, index) {
      this.splitSettingsShow.weekList.splice(index, 1);
    },
    // 添加一条数据
    addCategory() {
      let obj = {
        minRecharge: "",
        maxRecharge: "",
        totalShare: "",
      };
      this.splitSettingsShow.weekList.push(obj);
    },
    // 分成设置确定按钮
    async splitSettingsShowBtn() {
      let type = this.splitSettingsShow.weekList.every(
        (item) => item.minRecharge && item.maxRecharge && item.totalShare
      );
      if (!type) return this.$message.error("请填写完整!");
      const res = await setFissionExtensionSetting(this.splitSettingsShow);
      if(res.status == 200) this.splitSettingsShowDialog = false;
    },
    // 推广结算记录
    clickDetail() {
      this.$router.push({
        path: "/rootdatamanager/userbehavior-data/settlementRecords/settlementRecords",
      });
    },
  },
};
</script>
<style lang="scss" scoped>
$menuText: #14162e; // 侧边栏字体颜色
$hoverColor: #1d143c; // 鼠标停留主色调浅色
$mainColor: #3b425d; // 主色调

.op-container {
  margin: 20px;
}

.supervise-container {
  min-width: 500px;
  min-height: 260px;
  display: flex;
  flex-direction: row;
  justify-content: center;
}

.filter-container {
  width: 100%;
  height: 48px;
  line-height: 48px;

  .filter-item {
    display: inline-block;
    vertical-align: middle;
    margin-bottom: 10px;
  }

  .right-item {
    margin-right: 10px;
  }

  .kInput {
    position: absolute;
    right: 20px;
  }

  .filter-title {
    height: 48px;
    line-height: 48px;
    font-size: 16px;
    font-weight: 500;
    margin-right: 10px;
    color: #14162e;
  }

  .user-item {
    margin-left: 10px;
    margin-right: 20px;
  }

  .user-status,
  .account-status,
  .user-case {
    margin-right: 20px;
  }
}

.top-btn {
  margin: 10px 15px 10px 0px;
  font-size: 14px;
  color: #ffffff;
}

.kSelect .el-select .el-input .el-input__inner {
  width: 124px;
}

::v-deep .el-select .el-input.is-focus .el-input__inner {
  border-color: $mainColor;
}

::v-deep .el-input__inner:focus {
  border-color: $mainColor;
}

.el-form-item__label-wrap .el-form-item__label {
  float: none;
}

.dialog-openboxsetting {
  display: flex;
  flex-direction: row;
  justify-content: center;
  margin: 80px 80px;
}

.form-modify {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  margin: 10px 80px;

  .modify-right {
    margin-left: 80px;
  }
}

.percent-div {
  display: flex;
  flex-direction: row;
}

.avatar_robot {
  width: 80px;
  height: 80px;

  ::v-deep .avatar-uploader {
    .el-upload {
      border: 1px dashed #d9d9d9;
      border-radius: 6px;
      cursor: pointer;
      position: relative;
      overflow: hidden;
    }

    .el-upload:hover {
      border-color: $mainColor;
    }

    &-icon {
      font-size: 28px;
      color: #8c939d;
      width: 80px;
      height: 80px;
      line-height: 80px;
      text-align: center;
    }

    .avatar {
      width: 80px;
      height: 80px;
      display: block;
    }
  }
}

.finger-container {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;

  .content {
    display: inline-block;
    width: 60px;
    height: 50px;
    line-height: 50px;
  }

  .finger-delete {
    width: 40px;
    color: #3b425d;
    font-size: 14px;
    cursor: pointer;
  }
}

.kol-router {
  color: #3b425d;
  font-size: 14px;
}
.balance_btn {
  position: absolute;
  top: 0;
  right: 0;
}
</style>
